package org.nmgyjt.springboot.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.nmgyjt.springboot.entity.ApiRes;
import org.nmgyjt.springboot.entity.equipage.Equipage;
import org.nmgyjt.springboot.entity.materials.Materials;
import org.nmgyjt.springboot.entity.rescueTeam.RescueTeam;
import org.nmgyjt.springboot.entity.storeInfo.StoreInfo;
import org.nmgyjt.springboot.service.RescueTeamService;
import org.nmgyjt.springboot.service.StoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/cs/storeInfo")
public class StoreController {

    @Autowired
    private StoreService storeService;

//    @GetMapping("/getById")
//    public ApiRes getById(Long id) {
//        return ApiRes.ok(storeService.getById(id,""));
//    }

    @GetMapping("/getByDepId")
    public ApiRes getByDepId(String depId) {
        return ApiRes.ok(storeService.getBydepId(depId));
    }

    @GetMapping("/getStoreInfo")
    public ApiRes getStoreInfo(String id,String type,Integer current,Integer size,String storeName) {
        current=current==null?1:current;
        size=size==null?1000:size;
        Page<Materials> page=new Page<>(current,size);
        return ApiRes.ok(storeService.getStoreInfo(id,type,page,storeName));
    }

    @PostMapping("/saveOrUpdate")
    public ApiRes saveOrUpdate(@RequestBody StoreInfo storeInfo) {
        return storeService.insertOrUpdate(storeInfo);
    }

    @GetMapping("/list")
    public ApiRes list(String depId) {
        return ApiRes.ok(storeService.list());
    }

    @PostMapping("/deleteByDepId")
    public ApiRes deleteByDepId(String depId) {
        return storeService.deleteByDepId(depId);
    }
}
